/*
 * @Description:登录、校验接口
 * @Author: Liu Zhiwang
 * @Date: 2021-03-27 14:34:20
 * @LastEditTime: 2023-10-11 19:55:17
 * @LastEditors: Huang Junjie
 */
import request from '@/utils/request'
import { getToken as getCookieToken } from '@/utils/auth'

// 文件上传
export function upload(data) {
  return request({
    url: `/dfile/file/upload`,
    method: 'post',
    data: data
  })
}

// 文件下载
export function download(url) {
  return request({
    url: url,
    method: 'get',
    headers: {
      'Content-Type': 'application/octet-stream' // 流
    },
    responseType: 'blob',
    params: {
      access_token: getCookieToken()
    }
  })
}

export function getToken(query) {
  return request({
    url: 'auth/oauth/token',
    method: 'POST',
    data: query
  })
}

export function getRefreshToken(query) {
  return request({
    url: 'auth/oauth/token',
    method: 'post',
    params: query
  })
}

export function logout(query) {
  return request({
    url: 'auth/oauth/logout',
    method: 'post',
    params: query
  })
}

export function init(params) {
  return request({
    url: `/sysm/init/`,
    method: 'get',
    params: params
  })
}

export function changePwd(query) {
  return request({
    url: '/sysm/user/changePwd',
    method: 'post',
    data: query
  })
}

// 获取单位
export function getunitList(query) {
  return request({
    url: '/sysm/dept/unitList',
    method: 'get',
    params: query
  })
}

// 获取字典数据
export function getListByTypeCode(query) {
  return request({
    url: '/sysm/commonDict/listByTypeCode',
    method: 'get',
    params: query
  })
}

// 获取线路数据
export function getLineList(query) {
  return request({
    url: '/jjxtapi/basic/line',
    method: 'get',
    params: query
  })
}

// 获取线路所在区站
export function getSiteListByLineId(query) {
  return request({
    url: `/jjxtapi/basic/site/findAllSiteByLineIdAndSiteId`,
    method: 'get',
    params: query
  })
}

// 获取所有行别
export function getDirectionList(query) {
  return request({
    url: `/jjxtapi/basic/direction/getDirectionList`,
    method: 'get',
    params: query
  })
}

// 获取隧道
export function getTunnelList(query) {
  return request({
    url: `/jjxtapi/basic/tunnel/findTunnelByLineIdAndSiteId`,
    method: 'get',
    params: query
  })
}

// 获取股道
export function getTrackList(query) {
  return request({
    url: `/jjxtapi/basic/track/findTrackByLineIdAndSiteId`,
    method: 'get',
    params: query
  })
}

// 获取支柱号
export function getPillarList(query) {
  return request({
    url: `/jjxtapi/basic/pillar/findPillarList`,
    method: 'get',
    params: query
  })
}

// 获取单位下的人员
export function getStaffList(query) {
  return request({
    url: `/jjxtapi/staff/findStaffList`,
    method: 'get',
    params: query
  })
}

// 获取接触网工区
export function getJcwWorkAreaList(query) {
  return request({
    url: `/jjxtapi/dept/findWorkDeptList`,
    method: 'get',
    params: query
  })
}

// 获取顶部导航应用
export function getListEnable(query) {
  return request({
    url: '/sysm/platform/listEnable',
    method: 'get',
    params: query
  })
}

// 获取当前登入人可以管理的部门所属单位列表
export function findManageUnitDeptList(query) {
  return request({
    url: '/jjxtapi/dept/findManageUnitDeptList',
    method: 'get',
    params: query
  })
}

// 获取当前登入人可以管理的部门树
export function findManageDeptTree(query) {
  return request({
    url: `/jjxtapi/dept/findManageDeptTree`,
    method: 'get',
    params: query
  })
}

// 获取oracle字典数据
export function getListByDtId(query) {
  return request({
    url: '/jjxtapi/dict/findByDtId',
    method: 'get',
    params: query
  })
}

// 获取当前登入人可以管理的区间站场
export function findDeptManageSiteList(query) {
  return request({
    url: `/jjxtapi/dept/findDeptManageSiteList`,
    method: 'get',
    params: query
  })
}

// 获取字典数据
export function getListFindByDtId(query) {
  return request({
    url: '/jjxtapi/dict/findByDtId',
    method: 'get',
    params: query
  })
}

// 查询其他问题信息类型（不分页）
export function getOtherProblemTypeDataList() {
  return request({
    url: '/cdaily/otherInfoType/listData',
    method: 'get'
  })
}

// 获取当前部门及下属部门（参数：deptCode）
export function getDeptAndSubDeptList(query) {
  return request({
    url: '/jjxtapi/dept/getDeptAndSubDeptTree',
    method: 'get',
    params: query
  })
}

// 获取下属部门（参数：deptCode）
export function getSubDeptList(query) {
  return request({
    url: '/jjxtapi/dept/getSubDeptList',
    method: 'get',
    params: query
  })
}

// 获取人员通过部门、单位
export function findStaffByDeptUnit(query) {
  return request({
    url: '/jjxtapi/staff/findStaffListByDeptCodeAndMyUnitStaffList',
    method: 'get',
    params: query
  })
}

// 查询跳转的子系统地址，是否有权限，防止跳转404
// 参数：appCode 子系统编号，redirectUrl 跳转url
export function checkRedirectUrlPermission(params) {
  return request({
    url: '/sysm/menu/checkRedirectUrlPermission',
    method: 'GET',
    params
  })
}
